import 'package:flutter/material.dart';
import 'package:flutterroom/pages/home/tab_search/dataList.dart';
import 'package:flutterroom/pages/home/tab_search/searchWidget/item.dart';
import 'package:flutterroom/pages/my/until/common_picker.dart';

class SearchTitleBtn extends StatefulWidget {
  final ValueChanged<FilterBarResult> onChange;
  const SearchTitleBtn({Key key, this.onChange}) : super(key: key);
  @override
  _SearchTitleBtnState createState() => _SearchTitleBtnState();
}

class _SearchTitleBtnState extends State<SearchTitleBtn> {

bool isQuYu = false;
bool isFangShi = false;
bool isZuJing = false;
bool isShaiXuan = false;

String QuYuId = "";
String FangShiId = "";
String ZuJingId = "";
List<String> ShaiXuanId = [];

//区域
_onQuYuChange(context){
  setState(() {
    isQuYu =true;
  });
var result =CommonPicker.showPicker(
  context: context,
  value: 0,
  options: areaList.map((e) => e.name).toList()
);

result.then((value){
  if(value==null)return;
  setState(() {
    QuYuId =areaList[value].id;
    isQuYu =true;
  });

}).whenComplete((){
  setState(() {
    isQuYu =false;
  });
});
  _onChange();
}

//方式
_onFangShiChange(context){
   setState(() {
    isFangShi =true;
  });
var result =CommonPicker.showPicker(
  context: context,
  value: 0,
  options: rentTypeList.map((e) => e.name).toList()
);

result.then((value){
  if(value==null)return;
  setState(() {
    FangShiId =rentTypeList[value].id;
    isFangShi =true;
  });

}).whenComplete((){
  setState(() {
    isFangShi =false;
  });
});
  _onChange();
}

//租金
_onZuJingChange(context){
   setState(() {
    isZuJing =true;
  });
var result =CommonPicker.showPicker(
  context: context,
  value: 0,
  options: priceList.map((e) => e.name).toList()
);

result.then((value){
  if(value==null)return;
  setState(() {
    ZuJingId =priceList[value].id;
    isZuJing =true;
  });

}).whenComplete((){
  setState(() {
    isZuJing =false;
  });
});
  _onChange();
}
_onShaiXuanChange(context){}


_onChange(){
  if(widget.onChange!=null){
    widget.onChange(FilterBarResult(
      areaId: QuYuId,
      rentTypeId: FangShiId,
      priceId: ZuJingId,
      moreIds: ShaiXuanId
    ));
  }
}

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 10,right: 10),
      height: 41,
      decoration: BoxDecoration(border: Border(bottom: BorderSide(color: Colors.black12,width: 1))),
      child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[
        Item(title: "区域",isActive: isQuYu,onTap:_onQuYuChange),
        Item(title: "方式",isActive: isFangShi,onTap: _onFangShiChange,),
        Item(title: "租金",isActive: isZuJing,onTap: _onZuJingChange,),
        Item(title: "筛选",isActive: isShaiXuan,onTap: (context){},),
      ],),
    );
  }
}